<?php

/** 
 * amountHelper
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class  amountHelper{
    /**
     * toInt
     * 1,111,111.00 -> 1111111
     * @param   string   $str
     * @return  string   $str
     */
    public static function toInt($str){
        $str = str_replace(",", "", $str);
        $str = intval($str);
        return $str;
    }

    /**
     * toDecimal
     * 1,111,111.00 -> 1111111.00
     * @param   string   $str
     * @return  string   $str
     */
    public static function toDecimal($str){
        $str = str_replace(",", "", $str);
        $str = floatval($str);
        return $str;
    }

    /**
     * moneyFormat
     * 1111111.00 -> 1,111,111.00
     * @param   string   $number
     * @return  string   $str
     */
    public static function moneyFormat($number){
        $str = number_format($number, 2);
        return $str;
    }

    /**
     * numberRound
     * 数字四舍五入
     * @param   string  $number
     * @param   int     $count
     * @return  string  $str
     */
    public static function numberRound($number, $count=null){
        if(!is_numeric($number)){
            return $number;
        }
        if($count==0){
             return round($number, 0);
        }
        if ($count == null)
            if (strlen($dec) == 0)
                return round($number, 2);
            else 
                return $number;
        else 
            return round($number, $count);
    }

    /**
     * numberCut
     * 数字小数部分去除
     * @param   string  $number
     * @param   int     $count
     * @return  string  $str
     */
    public static function numberCut($number, $count = null){
        if(!is_numeric($number)){
            return $number;
        }
        $arrNumber = explode(".", $number);
        if ($count == null || $count == 0){
            return $arrNumber[0];
        } else {
            if(count($arrNumber) == 1 || strlen($arrNumber[1]) < $count){
                return $number;
            } else{
                $arrNumber[1] = substr($arrNumber[1], 0, $count);
                return implode(".", $arrNumber);
            }
        }
    }

    /**
     * roundUp
     * 数字进一
     * @param   string  $number
     * @return  string  $str
     */
    public static function roundUp($number){
        $number = floatval($number);
        $number = ceil($number);
        return $number;
    }
}